package com.appointment.controller;

import java.text.DateFormat;
import java.util.Date;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.appointment.dao.ScoresDao;
import com.appointment.entity.Score;
import com.appointment.util.formifEmpty;
import com.appointment.util.inputhanzi;
/**
 * 打印分数
 * @author WSD
 *
 */
@Controller
public class ScoreController {
	
	@Resource
	ScoresDao scoresdao;
	
	@RequestMapping("/score")
	public String score(){
		return "prograss";
	}
	
	@Transactional(rollbackFor={Exception.class})
	@RequestMapping("/addScore")
	public String addScore(Score score, Model model){
		//判断输入的名称格式
//		if(!inputhanzi.inputhz(score.getUsername())){
//			model.addAttribute("message", "姓名输入不准确");
//			return "prograss";
//		}
		if(!formifEmpty.scoreifEmpty(score)){
			return "redirect:/error";
		}
		//判断用户是否有未处理信息
		Score score1 = scoresdao.findScoredByStuNumber(score.getStu_number());
		if(score1!=null){
			model.addAttribute("message", "你已经上传");
			return "right";
		}
		//设置时间
		Date date = new Date();
		//String s = DateFormat.getDateInstance(DateFormat.DEFAULT).format(date);
		score.setTime(date);
		scoresdao.addScores(score);
		model.addAttribute("message", "上传成功");
		return "right";
	}
}
